﻿using Microsoft.Data.SqlClient;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json.Linq;
using SqlSugar;
using System.Data;
using System.Linq.Expressions;
using System.Numerics;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using VM.Common.DataUntil;

using VM.Common.Result;
using VM.Entity.EntityMap.Condition;
using VM.Entity.EntityMap.Member;
using VM.Entity.EntityMap.Menu;
using VM.Entity.EntityMap.MsgCode;
using VM.Entity.EntityMap.searchLog;
using VM.Entity.EntityMap.Token;
using VM.IBLL.SearchLog;
using VM.IDAL;
using static Dm.net.buffer.ByteArrayBuffer;

namespace VM.BLL.SearchLog
{
    public class SearchLogBLL : BaseBLL, ISearchLogBLL
    {

        private readonly ISqlSuggarDAL _ISqlSuggarDAL;
        public SearchLogBLL(ISqlSugarClient client, ISqlSuggarDAL sqlSuggarDAL)
        {
            _ISqlSuggarDAL = sqlSuggarDAL;
        }



        public ApiDataResult<sys_searchLog> addSearchLog(sys_searchLog obj)
        {
            //处理表头
            sys_searchLog menu = _ISqlSuggarDAL.Insert(obj);


            ApiDataResult<sys_searchLog> res = new ApiDataResult<sys_searchLog>();
            if (menu.id != 0)
            {
                res.code = 201;
                res.msg = "添加成功";
                res.data = menu;
            }
            else
            {

                res.code = 403;
                res.msg = "添加失败";
                res.data = null;
            }
            return res;
        }




        public ApiDataResult<PagingData<sys_searchLog>> getSearchLogList(int? UserId, string? Name, int? MenuId, int PageIndex = 0, int PageSize = 15)
        {



            List<Condition> list = new List<Condition>();
            Condition c = new Condition()
            {
                FieldName = "menuId",
                FieldValue = MenuId.ToString(),
                ConditionalType = 0
            };
            Condition c1 = new Condition()
            {
                FieldName = "createUserId",
                FieldValue = UserId.ToString(),
                ConditionalType = 0
            };
            list.Add(c);
            list.Add(c1);
            if (!Name.IsNullOrEmpty())
            {

                Condition c2 = new Condition()
                {
                    FieldName = "name",
                    FieldValue = Name.ToString(),
                    ConditionalType = 1
                };

                list.Add(c2);
            }

            Expression<Func<sys_searchLog, object>> funcOrderby = x => x.UseQty;

            PagingData<sys_searchLog> List = _ISqlSuggarDAL.QueryPageConditon(list, PageSize, PageIndex, funcOrderby, false);

            ApiDataResult<PagingData<sys_searchLog>> res = new ApiDataResult<PagingData<sys_searchLog>>();
            if (List.recordCount > 0)
            {
                res.code = 200;
                res.msg = "获取成功";

                res.data = List;




            }
            else
            {
                res.code = 200;
                res.msg = "无数据";
                res.data = null;

            }

            return res;
        }


        public Task<bool> updateSearchLog(sys_searchLog obj)
        {

            Task<bool> updateRes = _ISqlSuggarDAL.UpdateAsync(obj);


            return updateRes;
        }
    }



}
